<template>
  <div class="bgColor">
    <div style="padding:50px 80px">
      <el-page-header @back="goBack"> </el-page-header>
      <div class="artText">
        <h2>{{ formInfo.title }}</h2>
      </div>
      <div class="artContent">
        <span style="margin-right: 30px;"
          >发布时间：{{ formInfo.createTime }}</span
        >
        <span>来源：{{ formInfo.source }}</span>
      </div>
      <div class="content" v-html="formInfo.content"></div>
    </div>
  </div>
</template>
<script>
import _ from "lodash";

export default {
  data() {
    return {
      formInfo: {}
    };
  },
  watch: {
    $route(to, from) {
      // data数据操作
      if (this.$route.query.key) {
        this.getDetails();
      }
    }
  },
  created() {
    this.getDetails();
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    getDetails() {
      if (this.$route.query.key) {
        let id = this.$route.query.key;
        this.$store.dispatch("viewArticleUsingGETS", { id: id }).then(ret => {
          this.formInfo = ret.data;
          let re = /(<br\/>|<br>|<BR>|<BR\/>)/g;
          if (this.formInfo.subTitle) {
            this.formInfo.subTitle = this.formInfo.subTitle.replace(re, "\n");
          }

          this.formInfo.itemId = ret.data.itemId;
          if (this.formInfo.subTitle && this.formInfo.subTitle.length > 0) {
            this.checked = true;
          }
          if (
            this.formInfo.articleType &&
            this.formInfo.articleType.length > 0
          ) {
            this.checkList = _.cloneDeep(this.formInfo.articleType.split(","));
            this.showUrlEditor = this.formInfo.articleType.includes("j");
          }
          if (this.formInfo.basicThumbnails) {
            this.imageUrl1 = this.formInfo.basicThumbnails;
          }
        });
      }
    }
  }
};
</script>
<style scoped>
.content {
  margin-top: 30px;
}
.content /deep/ p {
  font-size: 16px !important;
}
.artContent {
  text-align: center;
  padding: 30px 0;
  color: gray;
  border-bottom: 1px solid rgba(224, 238, 249, 1);
}
.bgColor {
  margin: 50px 200px;
  background-color: white;
}
.artText {
  text-align: center;
  font-size: 25px;
  font-weight: bold;
}
</style>
